<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class information_controller extends admin_controller
{
    // Get list
    public function __construct()
    {
        parent::__construct();
        $this->page_title = 'Tickets check in';
        $this->table_name = 'information';
        $this->route_name = 'information_controller';
        $this->business_model = $this->information;
    }

    public function save($districtid)
    {
        $this->get_post_data();
        redirect($this->hook_redirect_url_after_save($districtid));
    }

    public function get_post_data()
    {

        $startTicketNumber = str_replace(' ','',$this->input->post('start_ticket_number'));
        $endTicketNumber = str_replace(' ','',$this->input->post('end_ticket_number'));
        $ticketTitle = $this->input->post('ticket_title');

        if(is_numeric($startTicketNumber) && is_numeric($endTicketNumber)){
            for($i = $startTicketNumber ; $i <= $endTicketNumber ; $i++){
                $post_data = array(
                    'ticket_number' => $i,
                    'ticket_title' => $ticketTitle,
                    'created_date' => time()
                );

                $this->db->insert($this->table_name,$post_data);
            }
        }

//        $post_data = array(
//            'file_path' => $file_path,
//            'parent' => $parent_string1,
//            'title' => $this->input->post('title'),
//            'content' => $this->input->post('content'),
//            'url' => $this->input->post('url'),
//            'lang_mapping' => $this->input->post('lang_mapping'),
//            'display_type' => $this->input->post('display_type'),
//            'modified_date' => time()
//        );


//        return array($post_data,$post_data1);
    }


    public function get_list_actions()
    {
        $actions = array();

        $actions[] = array(
            'text' => 'Thêm vé',
            'href' => base_url(). $this->base_admin_url .$this->route_name.'/update/-1',
            'view_change_method' => 'redirect'
        );
//        $actions[] = array(
//            'text' => 'Xóa',
//            'href' => base_url(). $this->base_admin_url .$this->route_name.'/delete',
//            'view_change_method' => 'submit'
//        );
        return $actions;
    }

    public function get_list()
    {

        $list = array();
        $news = $this->business_model->get_elements_checked_in();
        date_default_timezone_set('Asia/Bangkok');
        foreach($news as $item)
        {
            $actions = array();
//            $actions[] = array(
//                'text' => 'Sửa',
//                'href' => base_url(). $this->base_admin_url .$this->route_name.'/update/'.$item->id
//            );

            $list[] = array(
                'can_delete' => $item->id,
                'ticket_number' => $item->ticket_number,
                'ticket_title' => $item->ticket_title,
                'check_in' => date('d/m/Y - H:i',$item->check_in),
                'created_date' => date('d/m/Y - H:i',$item->created_date)
            );
        }
        return $list;
    }

    public function get_header_list()
    {
        $list = array();
        $list[] = 'Số vé';
        $list[] = 'Loại vé';
        $list[] = 'ngày check in';
        $list[] = 'Ngày tạo';
        return $list;
    }

    public function get_fields($id)
    {

        $fields = array();


        $fields[] = array(
            'text' => 'Số vé bắt đầu',
            'name' => 'start_ticket_number',
            'value' => '',
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Số vé kết thúc',
            'name' => 'end_ticket_number',
            'value' => '',
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Tên vé',
            'name' => 'ticket_title',
            'value' => '',
            'type' => 'text'
        );

        return $fields;
    }
}